{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this">订单管理</li>
        </ul>
        <div class="layui-tab-content">

            <form class="layui-form layui-form-pane" action="{:url('admin/ord/index')}" method="get">
                <div class="layui-inline">
                    <label class="layui-form-label">用户昵称:</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" value="{$nickname}" name="nickname"  placeholder="请输入用户昵称"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">订单号:</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" value="{$order_id}" name="orderId"  placeholder="请输入订单号"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">订单状态:</label>
                    <div class="layui-input-inline">
                        <select name="ostatus">
                            <option value="0" {if condition="$order_status eq 0"}selected="selected"{/if}>未付款</option>
                            <option value="1" {if condition="$order_status eq 1"}selected="selected"{/if}>未发货</option>
                            <option value="2" {if condition="$order_status eq 2"}selected="selected"{/if}>已发货</option>
                            <option value="3" {if condition="$order_status eq 3"}selected="selected"{/if}>确认收货</option>
                            <option value="4" {if condition="$order_status eq 4"}selected="selected"{/if}>订单完结</option>
                            <option value="5" {if condition="$order_status eq 5"}selected="selected"{/if}>订单取消</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn">搜索</button>
                </div>
            </form>
            <hr>

            <form action="" method="post" class="ajax-form">
                <div class="layui-tab-item layui-show">
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <td>订单编号</td>
                            <td width="120px">商品名称</td>
                            <td>商品图片</td>
                            <td width="60px">
                                <p>货品信息</p>
                                <p>数量</p>
                            </td>
                            <td width="60px">用户信息</td>
                            <td>总额</td>
                            <td width="70px">
                                <p>支付方式</p>
                                <p>付款交易号</p>
                            </td>
                            <td>发货信息</td>
                            <td width="60px">
                                <p>快递公司</p>
                                <p>快递单号</p>
                            </td>
                            <td>备注</td>
                            <td>订单状态</td>
                            <td>订单日期</td>
                        </tr>
                        </thead>
                        <tbody>
                        {foreach name="ord_list" item="vo"}
                            <tr>
                                <td>{$vo.order_id}</td>
                                <td>{$vo.goods_name}</td>
                                <td><img src="{$vo.goods_thumb}" alt="暂无图片" width="50px" height="50px"></td>
                                <td style="text-align: center;">
                                    <p>{$vo.goods_spec}</p>
                                    <p>{$vo.number}</p>
                                </td>
                                <td><img src="{$vo.headimgurl}" alt="暂无图片" width="50px" height="50px"/><br />{$vo.nickname}</td>
                                <td>{$vo.price}</td>
                                <td>
                                    <p>{if condition="$vo.pay_method == 'online'"}线上支付{elseif condition="$vo.pay_method == 'offline' "}线下支付{else}暂无{/if}</p>
                                    <p>微信:{$vo.source_order_id}</p>
                                </td>
                                <td>
                                    <p>收货人:{$vo.name}</p>
                                    <p>电话:{$vo.phone}</p>
                                    <p>收货地址:{$vo.province}{$vo.city}{$vo.area}{$vo.address}</p>
                                </td>
                                <td>
                                    {if empty($vo.courier_company) && ($vo.status==1)}
                                    <a class="layui-btn layui-btn-radius layui-btn-normal layui-btn-xs write-wl" data-id="{$vo.order_id}">填写物流</a>
                                    {else /}<p>{$vo.courier_company}</p>
                                    <p>{$vo.courier_code}</p>
                                    {if ($vo.status ==2)}
                                    <a class="layui-btn layui-btn-radius layui-btn-normal layui-btn-xs change-wl" data-courier-id="{$vo.courier_id}"  data-code="{$vo.courier_code}" data-id="{$vo.order_id}">修改物流</a>
                                    {/if}
                                    {/if}
                                </td>
                                <td>{$vo.remark}</td>
                                <td>
                                    <?php
                                    switch($vo['status']){
                                        case 0:
                                            echo "未付款";
                                            break;
                                        case 1:
                                            echo "未发货";
                                            break;
                                        case 2:
                                            echo "已发货";
                                            break;
                                        case 3:
                                            echo "确认收货";
                                            break;
                                        case 4:
                                            echo "订单完结";
                                            break;
                                        case 5:
                                            echo "取消订单";
                                            break;
                                    };
                                ?>
                                </td>
                                <td>{$vo.created_at}</td>
                            </tr>
                        {/foreach}
                        </tbody>
                    </table>
                    <!--分页-->
                    {$ord_list->render()}
                </div>
            </form>
        </div>
    </div>
</div>
<div id="model-bg" style="display: none;">
    <div>
        <div class="layui-form" action="" lay-filter="demo">
            <div class="layui-form-item">
                <label class="layui-form-label">订单号</label>
                <span style="display: block;padding-top: 10px;" id="order-id"></span>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">物流公司</label>
                <div class="layui-input-inline">
                    <select id="courier" lay-ignore autocomplete="off" >
                        {foreach $courier_list as $courier}
                        <option value="{$courier.id}">{$courier.courier_name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">物流单号</label>
                <input type="text" class="layui-input" style="width: auto;" id="code" placeholder="输入物流单号">
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
    $(".write-wl").on('click',function () {
        var id = $(this).attr("data-id");
        $("#order-id").text(id);
        //填写物流弹框
        layui.use('layer',function () {
            var layer = layui.layer;
            layer.open({
                type:1
                ,title:'填写物流'
                ,content:$("#model-bg")
                ,area: ['450px', '300px']
                ,btn:['确定','取消']
                ,yes:function () {
                    var courier_data = {
                        order_id:id,
                        courier_company:$('#courier').find("option:selected").text(),
                        courier_id:$('#courier').find("option:selected").val(),
                        courier_code:$("#code").val()
                    };
                    $.ajax({
                        url:'create_courier'
                        ,method:'POST'
                        ,data:courier_data
                        ,async:true
                        ,success:function (res) {
                            if(res.code == 1){
                                layer.msg(res.message);
                            }else{
                                layer.msg(res.message);
                            }
                        }
                    });
                    layer.closeAll();
                    setTimeout(function () {
                        window.location.reload();
                    },2000);
                }
            });
        });
    }) ;

    $(".change-wl").on('click',function () {
        var id = $(this).attr("data-id");
        var courier_id = $(this).attr("data-courier-id");
        var code = $(this).attr("data-code");
        $("#order-id").text(id);
        $('#courier option').each(function () {
            $(this).attr("selected",false);
        });
        $('#courier').find("option[value='"+courier_id+"']").attr("selected","selected");
        $("#code").attr("value",code);
        //填写物流弹框
        layui.use('layer',function () {
            var layer = layui.layer;
            layer.open({
                type:1
                ,title:'更改物流'
                ,content:$("#model-bg")
                ,area: ['450px', '300px']
                ,btn:['确定','取消']
                ,yes:function () {
                    var courier_data = {
                        order_id:id,
                        courier_company:$("#company").val(),
                        courier_code:$("#code").val()
                    };
                    $.ajax({
                        url:'update_courier'
                        ,method:'POST'
                        ,data:courier_data
                        ,async:true
                        ,success:function (res) {
                            if(res.code == 1){
                                layer.msg(res.message);
                            }else{
                                layer.msg(res.message);
                            }
                        }
                    });
                    layer.closeAll();
                    window.location.reload();
                }
            });
        });
    }) ;
</script>

{/block}

        